package com.springl.aop;



import java.lang.reflect.Method;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;


/**
 *
* @ClassName: LogAspect
* @Description: TODO(切面)
* @author antch,861710865@qq.com
* @date 2017年7月13日 下午1:53:34
*
 */
@Aspect
@Component
public class LogAspect {

	@Pointcut("@annotation(com.springl.aop.Action)")
	public void annotationPointcut() {

	}

	@After("annotationPointcut()")
	public void after(JoinPoint joinPoint) {
		MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
		Method method = methodSignature.getMethod();
		Action action = method.getAnnotation(Action.class);
		System.out.println("注解式拦截" + action.name());
	}

	/*
	 * 这个execution后括号中的字符串，*与com之间存在一个空格
	 */
	@Before("execution(* com.springl.aop.DemoMethodService.*(..))")
	public void before(JoinPoint joinPoint) {
		MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
		Method method = methodSignature.getMethod();
		System.out.println("方法规则拦截" + method.getName());
	}
}
